package models;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.*;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

import play.data.validation.*;
import play.db.jpa.Model;
import play.libs.Mail;



@Entity
public class Email extends Model {

	
	@Required
	public String source;


	
	@Required
	public String destination;

	public String subject;

	

	@Lob
	public String message;

	
	
	public Email(String source, String destination, String subject,
			String message) {
		this.source = source;
		this.destination = destination;
		this.subject = subject;
		this.message = message;
	}

	
	

	public void sendEmail() throws EmailException {

		SimpleEmail email = new SimpleEmail();
		email.setFrom("[Ideas Hub] " + source);
		email.addTo(destination);
		email.setSubject(subject);
		email.setMsg(message);
		Mail.send(email);

	}

}
